<template>
  <div class="body">
    <div class="articleList">
      <div
        v-for="article in articleList"
        :key="article.id"
        class="article"
        @click="goArticleDetail(article.id)"
      >
        <img
          v-if="article.coverImg"
          class="article-img"
          :src="article.coverImg"
        >
        <div class="center">
          <div class="title">{{ article.title }}</div>
          <div class="summary">{{ article.summary }}</div>
          <div class="time">{{ article.startTime }}</div>
        </div>
        <div class="source">[{{ article.source }}]</div>
      </div>
    </div>
    <el-pagination class="pagination" background prev-text="上一页" next-text="下一页" layout="prev, pager, next,total" :total="total" :page-size="pageSize" :page-num="pageNum" @current-change="pageChange" />
  </div>
</template>

<script>
import { getArticlePage } from '@/api/article/article'
export default {
  data() {
    return {
      articleList: [],
      total: 0,
      pageNum: 1,
      pageSize: 5
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    async load() {
      const categoryId = 6
      const data = await getArticlePage({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        categoryId: categoryId
      })
      this.articleList = data.data.records
      this.total = data.data.total
    },
    goArticleDetail(id) {
      this.$router.push(`articleDetail?id=${id}`)
    },
    pageChange(page) {
      this.pageNum = page
      this.load()
    }
  }
}
</script>

<style lang="scss" scoped>

.articleList{
  min-height: 700px;
}

.article{
  width: 1000px;
  border-bottom: 1px solid #999999;
  padding: 10px;
  height: 190px;
  cursor: pointer;

  .article-img{
    margin-right: 20px;
    width: 200px;
    height: 160px;
    object-fit: cover;
    float: left;
  }

  .center{
    float:left;
    width: 500px;
  }

  .title{
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
  }

  .summary{
    height: 100px;
    color:#999999;
    margin-right: 20px;
  }

  .time{
    color:#999999;
  }

  .source{
    float: right;
  }

}

.pagination{
  margin:20px 0;
}
</style>
